package com.testdocs.client.project;

import java.io.Serializable;

import com.testdocs.client.validation.SelfValidating;
import com.testdocs.client.validation.SimpleConstraint;
import com.testdocs.client.validation.ValidationConstraint;

@SuppressWarnings("serial")
public class ProjectInfo implements Serializable, SelfValidating {
	public String name;
	public String projectId;

	public ProjectInfo() {
	}

	public ProjectInfo(String name, String projectId) {
		this.name = name;
		this.projectId = projectId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public boolean equals(Object projectInfo) {
		return (projectInfo instanceof ProjectInfo) &&
			(getProjectId() == ((ProjectInfo)projectInfo).getProjectId());
	}

	@Override
	public ValidationConstraint[] selfValidate() {
		if (name == null || name.length() == 0) {
			ValidationConstraint constraint = new SimpleConstraint("Project name should be specified", "projectName");
			return new ValidationConstraint[] {constraint};
		} else if (name.length() > 256) {
			ValidationConstraint constraint = new SimpleConstraint("Project name should not be longer than 256 symbols", "projectName");
			return new ValidationConstraint[] {constraint};			
		} else {
			return null;
		}
	}
}
